home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.event.TreeModelEvent;
- import com.sun.java.swing.event.TreeModelListener;
- import com.sun.java.swing.event.TreeSelectionEvent;
- import com.sun.java.swing.event.TreeSelectionListener;
- import com.sun.java.swing.plaf.TreeUI;
- import com.sun.java.swing.tree.DefaultMutableTreeNode;
- import com.sun.java.swing.tree.RowMapper;
- import com.sun.java.swing.tree.TreeModel;
- import com.sun.java.swing.tree.TreeNode;
- import com.sun.java.swing.tree.TreePath;
- import com.sun.java.swing.tree.TreeSelectionModel;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public abstract class AbstractTreeUI extends TreeUI implements Serializable, TreeModelListener, RowMapper, TreeSelectionListener {
- protected transient TreeModel treeModel;
- protected boolean rootVisible;
- protected VisibleTreeNode treeCacheRoot;
- protected Vector visibleNodes = new Vector();
- protected boolean updateNodeSizes;
- protected int rowHeight = 16;
- protected boolean showsRootHandles;
- protected TreeSelectionModel treeSelectionModel;
- protected LargeTreeModelNode largeRoot;
- protected boolean largeModel;
- protected int largeRowCount;
-
- public void collapsePath(TreePath path) {
- if (!this.largeModel) {
- VisibleTreeNode[] nodePath = this.getNodesForTreePath(path, false, true);
- if (nodePath != null) {
- int counter = 0;
-
- for(int maxCounter = nodePath.length - 1; counter < maxCounter; ++counter) {
- if (!nodePath[counter].isExpanded()) {
- nodePath[counter].expand();
- }
- }
-
- if (nodePath.length > 0) {
- nodePath[counter].collapse();
- }
- }
- } else if (path != null) {
- LargeTreeModelNode node = this.getLargeTreeModelNodeForPath(path.getPath(), false, true);
- if (node != null) {
- node.collapse(true);
- }
- }
-
- }
-
- public void collapseRow(int row) {
- if (row >= 0 && row < this.getRowCount()) {
- if (!this.largeModel) {
- this.getNode(row).collapse();
- } else {
- LargeTreeModelNode node = this.getLargeTreeModelNodeForRow(row, false);
- if (node != null) {
- node.collapse(true);
- }
- }
- }
-
- }
-
- protected LargeTreeModelNode createLargeTreeModelNodeForValue(Object value, int childIndex) {
- return new LargeTreeModelNode(this, value, childIndex);
- }
-
- protected VisibleTreeNode createNodeAt(VisibleTreeNode parent, int childIndex) {
- VisibleTreeNode newChildNode;
- try {
- Object newValue = this.treeModel.getChild(parent.getValue(), childIndex);
- newChildNode = this.createNodeForValue(newValue, -1);
- ((DefaultMutableTreeNode)parent).insert(newChildNode, childIndex);
- } catch (Exception var8) {
- newChildNode = null;
- }
-
- boolean isParentRoot = parent == this.treeCacheRoot;
- if (newChildNode != null && parent.isExpanded() && (parent.getRow() != -1 || isParentRoot)) {
- int newRow;
- if (childIndex == 0) {
- if (isParentRoot && !this.isRootVisible()) {
- newRow = 0;
- } else {
- newRow = parent.getRow() + 1;
- }
- } else if (childIndex == ((DefaultMutableTreeNode)parent).getChildCount()) {
- newRow = parent.getLastVisibleNode().getRow() + 1;
- } else {
- VisibleTreeNode previousNode = (VisibleTreeNode)((DefaultMutableTreeNode)parent).getChildAt(childIndex - 1);
- newRow = previousNode.getLastVisibleNode().getRow() + 1;
- }
-
- this.visibleNodes.insertElementAt(newChildNode, newRow);
- }
-
- return newChildNode;
- }
-
- protected VisibleTreeNode createNodeForValue(Object value, int index) {
- return new VisibleTreeNode(this, value, index);
- }
-
- protected AbstractTreePath createTreePathFor(VisibleTreeNode node) {
- return new AbstractTreePath(((DefaultMutableTreeNode)node).getUserObjectPath(), node);
- }
-
- protected boolean ensureLargePathIsExpanded(TreePath path, boolean expandLast) {
- Object[] aPath = path.getPath();
- if (aPath != null) {
- int pathLength = aPath.length;
- if (this.treeModel.isLeaf(aPath[pathLength - 1])) {
- if (pathLength == 1) {
- aPath = null;
- } else {
- Object[] tPath = new Object[pathLength - 1];
- System.arraycopy(aPath, 0, tPath, 0, pathLength - 1);
- aPath = tPath;
- expandLast = true;
- }
- }
-
- if (aPath != null) {
- LargeTreeModelNode lastNode = this.getLargeTreeModelNodeForPath(aPath, false, true);
- if (lastNode != null) {
- Object[] expPath = ((DefaultMutableTreeNode)lastNode).getPath();
- int maxCounter = expPath.length - 1;
-
- for(int counter = 0; counter < maxCounter; ++counter) {
- ((LargeTreeModelNode)expPath[counter]).expand(true);
- }
-
- if (expandLast) {
- ((LargeTreeModelNode)expPath[maxCounter]).expand(true);
- }
-
- return true;
- }
- }
- }
-
- return false;
- }
-
- protected TreePath ensurePathIsAbstract(TreePath path, VisibleTreeNode node) {
- return (TreePath)(path != null && !(path instanceof AbstractTreePath) ? new AbstractTreePath(path.getPath(), node) : path);
- }
-
- protected VisibleTreeNode[] ensurePathIsExpanded(TreePath path, boolean expandLast) {
- VisibleTreeNode[] nodePath = this.getNodesForTreePath(path, false, true);
- if (nodePath != null) {
- int counter = 0;
-
- for(int maxCounter = expandLast ? nodePath.length : nodePath.length - 1; counter < maxCounter; ++counter) {
- if (!nodePath[counter].isExpanded()) {
- nodePath[counter].expand();
- }
- }
- }
-
- return nodePath;
- }
-
- public void expandPath(TreePath path) {
- if (path != null) {
- if (!this.largeModel) {
- this.ensurePathIsExpanded(path, true);
- } else {
- this.ensureLargePathIsExpanded(path, true);
- }
- }
-
- }
-
- public void expandRow(int row) {
- if (row >= 0 && row < this.getRowCount()) {
- if (!this.largeModel) {
- this.getNode(row).expand();
- } else {
- LargeTreeModelNode node = this.getLargeTreeModelNodeForRow(row, true);
- if (node != null) {
- node.expand(true);
- }
- }
- }
-
- }
-
- public TreePath getClosestPathForLocation(int x, int y) {
- if (this.getRowCount() == 0) {
- return null;
- } else {
- int row = this.getRowContainingYLocation(y);
- return !this.largeModel ? this.getNode(row).getTreePath() : this.getLargePathForRow(row);
- }
- }
-
- public int getClosestRowForLocation(int x, int y) {
- return this.getRowCount() == 0 ? -1 : this.getRowContainingYLocation(y);
- }
-
- protected abstract Rectangle getLargeBoundsOf(LargeTreeModelNode var1, int var2, Object var3);
-
- protected LargeTreeModelNode getLargeParentAndChildIndexOfRow(int row, int[] cIndex) {
- int[] rowIndex = new int[1];
- LargeTreeModelNode[] retNode = new LargeTreeModelNode[1];
- boolean[] isParent = new boolean[1];
- if (this.isRootVisible()) {
- rowIndex[0] = 0;
- } else {
- rowIndex[0] = -1;
- }
-
- if (this.largeRoot.getPathForRow(row, rowIndex, (TreePath[])null, retNode, isParent, cIndex)) {
- if (isParent[0]) {
- return retNode[0];
- } else {
- cIndex[0] = retNode[0].getChildIndex();
- return (LargeTreeModelNode)retNode[0].getParent();
- }
- } else {
- return null;
- }
- }
-
- protected TreePath getLargePathForRow(int row) {
- int[] rowIndex = new int[1];
- TreePath[] retPath = new TreePath[1];
- if (this.isRootVisible()) {
- rowIndex[0] = 0;
- } else {
- rowIndex[0] = -1;
- }
-
- return this.largeRoot.getPathForRow(row, rowIndex, retPath, (LargeTreeModelNode[])null, (boolean[])null, (int[])null) ? retPath[0] : null;
- }
-
- protected int getLargeRowForPath(Object[] path) {
- int[] rowIndex = new int[1];
- if (this.isRootVisible()) {
- rowIndex[0] = 0;
- } else {
- rowIndex[0] = -1;
- }
-
- return path != null && this.largeRoot.getRow(path, 0, path.length, true, rowIndex) ? rowIndex[0] : -1;
- }
-
- protected LargeTreeModelNode getLargeTreeModelNodeForPath(Object[] path, boolean onlyIfVisible, boolean shouldCreate) {
- if (path != null) {
- int pathLength = path.length;
- if (pathLength > 0) {
- return this.getLargeTreeModelNodeForPath(path, onlyIfVisible, shouldCreate, pathLength);
- }
- }
-
- return null;
- }
-
- protected LargeTreeModelNode getLargeTreeModelNodeForPath(Object[] path, boolean onlyIfVisible, boolean shouldCreate, int pathLength) {
- if (!path[0].equals(this.largeRoot.getUserObject())) {
- return null;
- } else {
- LargeTreeModelNode lastParent = this.largeRoot;
-
- for(int counter = 1; counter < pathLength; ++counter) {
- if (onlyIfVisible && !lastParent.isExpanded) {
- return null;
- }
-
- int wantIndex = this.treeModel.getIndexOfChild(((DefaultMutableTreeNode)lastParent).getUserObject(), path[counter]);
- if (wantIndex < 0) {
- throw new RuntimeException("invalid index " + wantIndex + " for path " + path[counter]);
- }
-
- int maxCCounter = ((DefaultMutableTreeNode)lastParent).getChildCount();
- LargeTreeModelNode beginLastParent = lastParent;
-
- for(int cCounter = 0; cCounter < maxCCounter; ++cCounter) {
- LargeTreeModelNode aNode = (LargeTreeModelNode)((DefaultMutableTreeNode)lastParent).getChildAt(cCounter);
- if (aNode.childIndex == wantIndex) {
- lastParent = aNode;
- cCounter = maxCCounter;
- } else if (aNode.childIndex > wantIndex) {
- if (!shouldCreate) {
- return null;
- }
-
- LargeTreeModelNode newNode = this.createLargeTreeModelNodeForValue(path[counter], wantIndex);
- ((DefaultMutableTreeNode)lastParent).insert(newNode, cCounter);
- lastParent = newNode;
- cCounter = maxCCounter;
- }
- }
-
- if (beginLastParent == lastParent) {
- if (!shouldCreate) {
- return null;
- }
-
- LargeTreeModelNode newNode = this.createLargeTreeModelNodeForValue(path[counter], wantIndex);
- ((DefaultMutableTreeNode)lastParent).add(newNode);
- lastParent = newNode;
- }
- }
-
- return lastParent;
- }
- }
-
- protected LargeTreeModelNode getLargeTreeModelNodeForRow(int row, boolean shouldCreate) {
- int[] rowIndex = new int[1];
- int[] cIndex = new int[1];
- LargeTreeModelNode[] retNode = new LargeTreeModelNode[1];
- boolean[] isParent = new boolean[1];
- if (this.isRootVisible()) {
- rowIndex[0] = 0;
- } else {
- rowIndex[0] = -1;
- }
-
- if (this.largeRoot.getPathForRow(row, rowIndex, (TreePath[])null, retNode, isParent, cIndex)) {
- if (isParent[0]) {
- if (shouldCreate) {
- Object childUO = this.treeModel.getChild(retNode[0].getUserObject(), cIndex[0]);
- if (this.treeModel.isLeaf(childUO)) {
- return null;
- } else {
- LargeTreeModelNode newNode = this.createLargeTreeModelNodeForValue(childUO, cIndex[0]);
- retNode[0].addLargeTreeModelNode(newNode);
- return newNode;
- }
- } else {
- return null;
- }
- } else {
- return retNode[0];
- }
- } else {
- return null;
- }
- }
-
- public int getMaxNodeWidth() {
- int maxWidth = 0;
- if (!this.largeModel) {
- for(int counter = this.getRowCount() - 1; counter >= 0; --counter) {
- VisibleTreeNode node = this.getNode(counter);
- int nodeMaxX;
- if ((nodeMaxX = node.getPreferredSize().width + this.getXOriginOfNode(node)) > maxWidth) {
- maxWidth = nodeMaxX;
- }
- }
- } else {
- for(int counter = this.getRowCount() - 1; counter >= 0; --counter) {
- Rectangle var5 = this.getRowBounds(counter);
- maxWidth = Math.max(maxWidth, var5.x + var5.width);
- }
- }
-
- return maxWidth;
- }
-
- public int getMaxSelectionRow() {
- return this.treeSelectionModel != null ? this.treeSelectionModel.getMaxSelectionRow() : -1;
- }
-
- public int getMinSelectionRow() {
- return this.treeSelectionModel != null ? this.treeSelectionModel.getMinSelectionRow() : -1;
- }
-
- public TreeModel getModel() {
- return this.treeModel;
- }
-
- public VisibleTreeNode getNode(int row) {
- return (VisibleTreeNode)this.visibleNodes.elementAt(row);
- }
-
- public VisibleTreeNode getNodeForPath(Object[] path, boolean onlyIfVisible, boolean shouldCreate) {
- VisibleTreeNode[] nodes = this.getNodesForPath(path, onlyIfVisible, shouldCreate);
- return nodes != null && nodes.length > 0 ? nodes[nodes.length - 1] : null;
- }
-
- protected VisibleTreeNode getNodeForTreePath(TreePath path, boolean onlyIfVisible, boolean shouldCreate) {
- if (this.isAbstractTreePath(path, onlyIfVisible, shouldCreate)) {
- VisibleTreeNode vtn = ((AbstractTreePath)path).node;
- if (vtn == null) {
- return null;
- } else {
- return onlyIfVisible && !vtn.isVisible() ? null : vtn;
- }
- } else {
- return path != null ? this.getNodeForPath(path.getPath(), onlyIfVisible, shouldCreate) : null;
- }
- }
-
- public VisibleTreeNode[] getNodesForPath(Object[] path, boolean onlyIfVisible, boolean shouldCreate) {
- if (path != null && path.length > 0 && this.treeModel != null) {
- if (!this.treeCacheRoot.getValue().equals(path[0])) {
- return null;
- } else {
- VisibleTreeNode retNode = this.treeCacheRoot;
- int counter = 1;
- if (onlyIfVisible && path.length > 1 && !retNode.isExpanded()) {
- return null;
- } else {
- VisibleTreeNode[] nodePath = new VisibleTreeNode[path.length];
- nodePath[0] = retNode;
-
- while(retNode != null && counter < path.length) {
- VisibleTreeNode newNode = null;
- Enumeration childEnum = retNode.getLoadedChildren(shouldCreate);
-
- while(childEnum.hasMoreElements() && newNode == null) {
- newNode = (VisibleTreeNode)childEnum.nextElement();
- if (!newNode.getValue().equals(path[counter])) {
- newNode = null;
- }
- }
-
- retNode = newNode;
- nodePath[counter] = newNode;
- ++counter;
- if (newNode != null && onlyIfVisible && counter < path.length && !newNode.isExpanded()) {
- retNode = null;
- }
- }
-
- return retNode != null ? nodePath : null;
- }
- }
- } else {
- return null;
- }
- }
-
- protected VisibleTreeNode[] getNodesForTreePath(TreePath path, boolean onlyIfVisible, boolean shouldCreate) {
- if (this.isAbstractTreePath(path, onlyIfVisible, shouldCreate)) {
- VisibleTreeNode vtn = ((AbstractTreePath)path).node;
- if (vtn == null) {
- return null;
- } else if (onlyIfVisible && !vtn.isVisible()) {
- return null;
- } else {
- TreeNode[] tPath = ((DefaultMutableTreeNode)vtn).getPath();
- VisibleTreeNode[] cPath = new VisibleTreeNode[tPath.length];
- System.arraycopy(tPath, 0, cPath, 0, tPath.length);
- return cPath;
- }
- } else {
- return path != null ? this.getNodesForPath(path.getPath(), onlyIfVisible, shouldCreate) : null;
- }
- }
-
- public Rectangle getPathBounds(TreePath path) {
- if (!this.largeModel) {
- VisibleTreeNode node = this.getNodeForTreePath(path, true, false);
- if (node != null) {
- return node.getNodeBounds();
- }
- } else if (path != null) {
- return this.getRowBounds(this.getRowForPath(path));
- }
-
- return null;
- }
-
- public TreePath getPathForRow(int row) {
- if (row >= 0 && row < this.getRowCount()) {
- return !this.largeModel ? this.getNode(row).getTreePath() : this.getLargePathForRow(row);
- } else {
- return null;
- }
- }
-
- public TreePath[] getPathsForRows(int[] rows) {
- if (rows == null) {
- return null;
- } else {
- int numRows = rows.length;
- TreePath[] paths = new TreePath[numRows];
-
- for(int counter = 0; counter < numRows; ++counter) {
- paths[counter] = this.getPathForRow(rows[counter]);
- }
-
- return paths;
- }
- }
-
- public Rectangle getRowBounds(int row) {
- if (row >= 0 && row < this.getRowCount()) {
- if (!this.largeModel) {
- return this.getNode(row).getNodeBounds();
- }
-
- if (row == 0 && this.isRootVisible()) {
- return this.getLargeBoundsOf((LargeTreeModelNode)null, 0, this.largeRoot.getUserObject());
- }
-
- int[] cIndex = new int[1];
- LargeTreeModelNode parent = this.getLargeParentAndChildIndexOfRow(row, cIndex);
- if (parent != null) {
- return this.getLargeBoundsOf(parent, row, this.treeModel.getChild(((DefaultMutableTreeNode)parent).getUserObject(), cIndex[0]));
- }
- }
-
- return null;
- }
-
- public int getRowContainingYLocation(int location) {
- if (this.isFixedRowHeight()) {
- return this.getRowCount() == 0 ? -1 : Math.max(0, Math.min(this.getRowCount() - 1, location / this.getRowHeight()));
- } else {
- int max;
- if ((max = this.getRowCount()) <= 0) {
- return -1;
- } else {
- int min = 0;
- int mid = 0;
-
- while(min < max) {
- mid = (max - min) / 2 + min;
- VisibleTreeNode node = (VisibleTreeNode)this.visibleNodes.elementAt(mid);
- int minY = node.getYOrigin();
- int maxY = minY + node.getPreferredSize().height;
- if (location < minY) {
- max = mid - 1;
- } else {
- if (location < maxY) {
- break;
- }
-
- min = mid + 1;
- }
- }
-
- if (min == max) {
- mid = min;
- if (min >= this.getRowCount()) {
- mid = this.getRowCount() - 1;
- }
- }
-
- return mid;
- }
- }
- }
-
- public int getRowCount() {
- return !this.largeModel ? this.visibleNodes.size() : this.largeRowCount;
- }
-
- public int getRowForPath(TreePath path) {
- if (path == null) {
- return -1;
- } else if (!this.largeModel) {
- VisibleTreeNode visNode = this.getNodeForTreePath(path, true, false);
- return visNode != null ? visNode.getRow() : -1;
- } else {
- return this.getLargeRowForPath(path.getPath());
- }
- }
-
- public int getRowHeight() {
- return this.rowHeight;
- }
-
- public int[] getRowsForPaths(TreePath[] paths) {
- if (paths == null) {
- return null;
- } else {
- int numPaths = paths.length;
- int[] rows = new int[numPaths];
-
- for(int counter = 0; counter < numPaths; ++counter) {
- rows[counter] = this.getRowForPath(paths[counter]);
- }
-
- return rows;
- }
- }
-
- public TreeSelectionModel getSelectionModel() {
- return this.treeSelectionModel;
- }
-
- public TreePath getSelectionPath() {
- return this.treeSelectionModel != null ? this.treeSelectionModel.getSelectionPath() : null;
- }
-
- public TreePath[] getSelectionPaths() {
- return this.treeSelectionModel != null ? this.treeSelectionModel.getSelectionPaths() : null;
- }
-
- public int[] getSelectionRows() {
- return this.treeSelectionModel != null ? this.treeSelectionModel.getSelectionRows() : null;
- }
-
- public boolean getShowsRootHandles() {
- return this.showsRootHandles;
- }
-
- public abstract Dimension getSizeOfNode(VisibleTreeNode var1, int var2);
-
- public Object getValue(int row) {
- if (!this.largeModel) {
- return this.getNode(row).getValue();
- } else {
- int[] cIndex = new int[1];
- LargeTreeModelNode eNode = this.getLargeParentAndChildIndexOfRow(row, cIndex);
- if (row == 0 && this.isRootVisible()) {
- return this.treeModel.getRoot();
- } else {
- return eNode != null ? this.treeModel.getChild(((DefaultMutableTreeNode)eNode).getUserObject(), cIndex[0]) : null;
- }
- }
- }
-
- public abstract int getXOriginOfNode(VisibleTreeNode var1);
-
- public int getYOriginOfRow(int row) {
- if (row < 0) {
- return -1;
- } else if (row >= this.getRowCount()) {
- return -1;
- } else {
- return this.isFixedRowHeight() ? row * this.getRowHeight() : this.getNode(row).getYOrigin();
- }
- }
-
- protected boolean isAbstractTreePath(TreePath path, boolean onlyIfVisible, boolean shouldCreate) {
- if (path != null && path instanceof AbstractTreePath) {
- AbstractTreePath atPath = (AbstractTreePath)path;
- if (atPath.node == null || atPath.getUI() == this) {
- if (atPath.node == null || !atPath.node.isValid) {
- atPath.node = this.getNodeForPath(path.getPath(), false, shouldCreate);
- if (atPath.node == null) {
- return false;
- }
- }
-
- return true;
- }
- }
-
- return false;
- }
-
- public boolean isCollapsed(int row) {
- return !this.isExpanded(row);
- }
-
- public boolean isCollapsed(TreePath path) {
- return !this.isExpanded(path);
- }
-
- public boolean isExpanded(int row) {
- if (!this.largeModel) {
- return this.getNode(row).isExpanded();
- } else {
- LargeTreeModelNode eNode = this.getLargeTreeModelNodeForRow(row, false);
- return eNode != null ? eNode.isExpanded() : false;
- }
- }
-
- public boolean isExpanded(TreePath path) {
- if (!this.largeModel) {
- VisibleTreeNode lastNode = this.getNodeForTreePath(path, true, false);
- if (lastNode != null) {
- return lastNode.isExpanded();
- }
- } else if (path != null) {
- LargeTreeModelNode lastNode = this.getLargeTreeModelNodeForPath(path.getPath(), true, false);
- if (lastNode != null && lastNode.isExpanded()) {
- return true;
- }
-
- return false;
- }
-
- return false;
- }
-
- public boolean isFixedRowHeight() {
- return this.rowHeight > 0;
- }
-
- public boolean isLargeModel() {
- return this.largeModel;
- }
-
- public boolean isLeaf(int row) {
- if (!this.largeModel) {
- VisibleTreeNode node = this.getNode(row);
- if (node != null) {
- return node.isLeaf();
- }
- } else {
- if (row == 0 && this.isRootVisible()) {
- return this.treeModel.isLeaf(this.treeModel.getRoot());
- }
-
- int[] childIndex = new int[1];
- LargeTreeModelNode parent = this.getLargeParentAndChildIndexOfRow(row, childIndex);
- if (parent != null) {
- return this.treeModel.isLeaf(this.treeModel.getChild(((DefaultMutableTreeNode)parent).getUserObject(), childIndex[0]));
- }
- }
-
- return true;
- }
-
- public boolean isPathSelected(TreePath path) {
- return this.treeSelectionModel != null ? this.treeSelectionModel.isPathSelected(path) : false;
- }
-
- public boolean isRootVisible() {
- return this.rootVisible;
- }
-
- public boolean isRowSelected(int row) {
- return this.treeSelectionModel != null ? this.treeSelectionModel.isRowSelected(row) : false;
- }
-
- public boolean isSelectedIndex(int row) {
- return this.treeSelectionModel != null ? this.treeSelectionModel.isRowSelected(row) : false;
- }
-
- public boolean isVisible(TreePath path) {
- if (!this.largeModel) {
- VisibleTreeNode lastNode = this.getNodeForTreePath(path, true, false);
- if (lastNode != null) {
- return true;
- }
- } else if (path != null) {
- Object[] oPath = path.getPath();
- if (oPath != null) {
- int pathLength = oPath.length;
- if (pathLength > 0) {
- if (this.treeModel.isLeaf(oPath[pathLength - 1]) && pathLength > 1) {
- Object[] tempPath = new Object[pathLength - 1];
- System.arraycopy(oPath, 0, tempPath, 0, pathLength - 1);
- LargeTreeModelNode var7 = this.getLargeTreeModelNodeForPath(tempPath, true, false);
- if (var7 != null && var7.isVisible() && var7.isExpanded()) {
- return true;
- }
-
- return false;
- }
-
- LargeTreeModelNode lastNode = this.getLargeTreeModelNodeForPath(oPath, true, false);
- return lastNode.isVisible();
- }
- }
- }
-
- return false;
- }
-
- public void makeVisible(TreePath path) {
- if (!this.largeModel) {
- this.ensurePathIsExpanded(path, false);
- } else {
- this.ensureLargePathIsExpanded(path, false);
- }
-
- }
-
- protected abstract void pathWasCollapsed(TreePath var1);
-
- protected abstract void pathWasExpanded(TreePath var1);
-
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
- s.defaultReadObject();
- Vector values = (Vector)s.readObject();
- int indexCounter = 0;
- int maxCounter = values.size();
- if (indexCounter < maxCounter && values.elementAt(indexCounter).equals("treeModel")) {
- ++indexCounter;
- this.treeModel = (TreeModel)values.elementAt(indexCounter);
- ++indexCounter;
- }
-
- if (indexCounter < maxCounter && values.elementAt(indexCounter).equals("treeSelectionModel")) {
- ++indexCounter;
- this.treeSelectionModel = (TreeSelectionModel)values.elementAt(indexCounter);
- ++indexCounter;
- }
-
- }
-
- public void rebuild() {
- if (!this.largeModel && this.treeCacheRoot != null) {
- this.treeCacheRoot.markInvalid();
- }
-
- if (this.treeModel != null) {
- if (!this.largeModel) {
- this.largeRoot = null;
- this.treeCacheRoot = this.createNodeForValue(this.treeModel.getRoot(), 0);
- this.visibleNodes.removeAllElements();
- if (this.isRootVisible()) {
- this.visibleNodes.addElement(this.treeCacheRoot);
- }
-
- if (!this.treeCacheRoot.isExpanded()) {
- this.treeCacheRoot.expand();
- } else {
- Enumeration cursor = this.treeCacheRoot.children();
-
- while(cursor.hasMoreElements()) {
- this.visibleNodes.addElement(cursor.nextElement());
- }
-
- if (!this.isFixedRowHeight()) {
- this.updateYLocationsFrom(0);
- }
- }
- } else {
- this.treeCacheRoot = null;
- this.visibleNodes.removeAllElements();
- this.largeRoot = this.createLargeTreeModelNodeForValue(this.treeModel.getRoot(), 0);
- if (this.isRootVisible()) {
- this.largeRowCount = 1;
- } else {
- this.largeRowCount = 0;
- }
-
- this.largeRoot.expand(true);
- }
- } else {
- this.visibleNodes.removeAllElements();
- this.treeCacheRoot = null;
- this.largeRoot = null;
- this.largeRowCount = 0;
- }
-
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.clearSelection();
- }
-
- this.visibleNodesChanged();
- }
-
- public void setLargeModel(boolean largeModel) {
- if (this.largeModel != largeModel) {
- this.largeModel = largeModel;
- if (largeModel && this.rowHeight <= 0) {
- this.rowHeight = 16;
- }
-
- this.rebuild();
- }
-
- }
-
- public void setModel(TreeModel newModel) {
- TreeModel oldModel = this.treeModel;
- if (newModel != oldModel) {
- if (oldModel != null) {
- oldModel.removeTreeModelListener(this);
- }
-
- this.treeModel = newModel;
- if (this.treeModel != null) {
- this.treeModel.addTreeModelListener(this);
- }
-
- this.rebuild();
- }
-
- }
-
- public void setRootVisible(boolean rootVisible) {
- if (rootVisible != this.rootVisible) {
- this.rootVisible = rootVisible;
- if (this.treeModel != null) {
- if (!this.largeModel) {
- if (this.rootVisible) {
- this.treeCacheRoot.updatePreferredSize(0);
- this.visibleNodes.insertElementAt(this.treeCacheRoot, 0);
- } else if (this.visibleNodes.size() > 0) {
- this.visibleNodes.removeElementAt(0);
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.removeSelectionPath(this.treeCacheRoot.getTreePath());
- }
- }
-
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.resetRowSelection();
- }
-
- if (this.getRowCount() > 0) {
- this.getNode(0).setYOrigin(0);
- }
-
- this.updateYLocationsFrom(0);
- this.visibleNodesChanged();
- } else {
- if (this.rootVisible) {
- ++this.largeRowCount;
- } else {
- --this.largeRowCount;
- }
-
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.clearSelection();
- }
-
- this.visibleNodesChanged();
- }
- }
- }
-
- }
-
- public void setRowHeight(int rowHeight) {
- if (rowHeight != this.rowHeight) {
- if (!this.largeModel) {
- this.rowHeight = rowHeight;
- if (!this.isFixedRowHeight() && this.visibleNodes.size() > 0) {
- this.updateNodeSizes(true);
- } else if (this.isFixedRowHeight()) {
- for(int counter = this.getRowCount() - 1; counter >= 0; --counter) {
- this.getNode(counter).getPreferredSize().height = rowHeight;
- }
- }
-
- this.visibleNodesChanged();
- } else {
- if (rowHeight <= 0) {
- throw new IllegalArgumentException("AbstractTreeUI.setRowHeight() row height must be > 0 for large models");
- }
-
- this.rowHeight = rowHeight;
- this.visibleNodesChanged();
- }
- }
-
- }
-
- public void setSelectionModel(TreeSelectionModel newLSM) {
- if (this.treeSelectionModel != newLSM) {
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.removeTreeSelectionListener(this);
- this.treeSelectionModel.setRowMapper((RowMapper)null);
- }
-
- this.treeSelectionModel = newLSM;
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.addTreeSelectionListener(this);
- this.treeSelectionModel.setRowMapper(this);
- this.treeSelectionModel.resetRowSelection();
- }
- }
-
- }
-
- public void setShowsRootHandles(boolean newValue) {
- if (this.showsRootHandles != newValue) {
- this.showsRootHandles = newValue;
- this.visibleNodesChanged();
- }
-
- }
-
- public synchronized void treeNodesChanged(TreeModelEvent e) {
- if (e != null) {
- if (this.largeModel) {
- this.visibleNodesChanged();
- } else {
- int[] changedIndexs = e.getChildIndices();
- VisibleTreeNode changedNode = this.getNodeForPath(e.getPath(), false, false);
- if (changedNode != null) {
- Object changedValue = changedNode.getValue();
- changedNode.updatePreferredSize();
- if (changedIndexs != null) {
- for(int counter = 0; counter < changedIndexs.length; ++counter) {
- try {
- VisibleTreeNode changedChildNode = (VisibleTreeNode)((DefaultMutableTreeNode)changedNode).getChildAt(changedIndexs[counter]);
- ((DefaultMutableTreeNode)changedChildNode).setUserObject(this.treeModel.getChild(changedValue, changedIndexs[counter]));
- changedChildNode.updatePreferredSize();
- } catch (Exception var7) {
- }
- }
- }
-
- if (!this.isFixedRowHeight()) {
- int aRow = changedNode.getRow();
- if (aRow != -1) {
- this.updateYLocationsFrom(aRow);
- }
- }
-
- this.visibleNodesChanged();
- }
- }
- }
-
- }
-
- public synchronized void treeNodesInserted(TreeModelEvent e) {
- if (e != null && !this.largeModel) {
- int[] changedIndexs = e.getChildIndices();
- VisibleTreeNode changedParent = this.getNodeForPath(e.getPath(), false, false);
- if (changedParent != null && changedIndexs != null && changedIndexs.length > 0) {
- if (changedParent.hasBeenExpanded()) {
- changedParent.getValue();
- boolean maxCounter = changedParent == this.treeCacheRoot && !this.rootVisible || changedParent.getRow() != -1 && changedParent.isExpanded();
-
- for(int isVisible = 0; isVisible < changedIndexs.length; ++isVisible) {
- this.createNodeAt(changedParent, changedIndexs[isVisible]);
- }
-
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.resetRowSelection();
- }
-
- if (!this.isFixedRowHeight() && maxCounter) {
- if (changedParent == this.treeCacheRoot) {
- this.updateYLocationsFrom(0);
- } else {
- this.updateYLocationsFrom(changedParent.getRow());
- }
-
- this.visibleNodesChanged();
- } else if (maxCounter) {
- this.visibleNodesChanged();
- }
- } else {
- changedParent.modelChildCountChanged();
- }
- }
- } else if (e != null) {
- LargeTreeModelNode changedParent = this.getLargeTreeModelNodeForPath(e.getPath(), false, false);
- int[] changedIndexs = e.getChildIndices();
- int makeVisible;
- if (changedParent != null && changedIndexs != null && (makeVisible = changedIndexs.length) > 0) {
- boolean isVisible = changedParent.isVisible() && changedParent.isExpanded();
-
- for(int counter = 0; counter < makeVisible; ++counter) {
- changedParent.childInsertedAtModelIndex(changedIndexs[counter]);
- if (isVisible) {
- ++this.largeRowCount;
- }
- }
-
- if (isVisible && this.treeSelectionModel != null) {
- this.treeSelectionModel.resetRowSelection();
- }
-
- if (isVisible) {
- this.visibleNodesChanged();
- } else {
- changedParent.modelChildCountChanged();
- }
- }
- }
-
- }
-
- public synchronized void treeNodesRemoved(TreeModelEvent e) {
- if (e != null && !this.largeModel) {
- int[] changedIndexs = e.getChildIndices();
- VisibleTreeNode maxCounter = this.getNodeForPath(e.getPath(), false, false);
- if (maxCounter != null && changedIndexs != null && changedIndexs.length > 0) {
- if (maxCounter.hasBeenExpanded()) {
- boolean parentPath = maxCounter == this.treeCacheRoot && !this.rootVisible || maxCounter.getRow() != -1 && maxCounter.isExpanded();
-
- for(int changedParentNode = changedIndexs.length - 1; changedParentNode >= 0; --changedParentNode) {
- try {
- VisibleTreeNode children = (VisibleTreeNode)((DefaultMutableTreeNode)maxCounter).getChildAt(changedIndexs[changedParentNode]);
- if (children.isExpanded()) {
- children.collapse(false);
- }
-
- if (parentPath) {
- int childPath = children.getRow();
- if (childPath != -1) {
- this.visibleNodes.removeElementAt(childPath);
- if (this.treeSelectionModel != null) {
- TreePath oldPath = children.getTreePath();
- this.treeSelectionModel.removeSelectionPath(oldPath);
- }
- }
- }
-
- ((DefaultMutableTreeNode)maxCounter).remove(children);
- } catch (Exception var12) {
- System.out.println("Exception removing node" + var12);
- }
- }
-
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.resetRowSelection();
- }
-
- if (!this.isFixedRowHeight() && parentPath) {
- if (maxCounter == this.treeCacheRoot) {
- if (this.getRowCount() > 0) {
- this.getNode(0).setYOrigin(0);
- }
-
- this.updateYLocationsFrom(0);
- } else {
- this.updateYLocationsFrom(maxCounter.getRow());
- }
-
- this.visibleNodesChanged();
- } else if (parentPath) {
- this.visibleNodesChanged();
- }
- } else {
- maxCounter.modelChildCountChanged();
- }
- }
- } else if (e != null) {
- Object[] parentPath = e.getPath();
- LargeTreeModelNode changedParentNode = this.getLargeTreeModelNodeForPath(parentPath, false, false);
- int[] changedIndexs = e.getChildIndices();
- int changedParentNode;
- if (changedParentNode != null && changedIndexs != null && (changedParentNode = changedIndexs.length) > 0) {
- Object[] children = e.getChildren();
- int parentPathLength = parentPath.length;
- boolean isVisible = changedParentNode.isVisible() && changedParentNode.isExpanded();
-
- for(int counter = 0; counter < changedParentNode; ++counter) {
- LargeTreeModelNode childNode = changedParentNode.childAtModelIndex(changedIndexs[counter]);
- if (childNode != null) {
- childNode.collapse(false);
- ((DefaultMutableTreeNode)changedParentNode).remove(childNode);
- }
-
- if (isVisible) {
- --this.largeRowCount;
- }
-
- changedParentNode.childRemovedAtModelIndex(changedIndexs[counter]);
- if (this.treeSelectionModel != null && children != null && children[counter] != null) {
- Object[] removedRow = new Object[parentPathLength + 1];
- System.arraycopy(parentPath, 0, removedRow, 0, parentPathLength);
- removedRow[parentPathLength] = children[counter];
- this.treeSelectionModel.removeSelectionPath(new TreePath(removedRow));
- }
- }
-
- if (isVisible) {
- if (this.treeSelectionModel != null) {
- this.treeSelectionModel.resetRowSelection();
- }
-
- this.visibleNodesChanged();
- } else {
- changedParentNode.modelChildCountChanged();
- }
- }
- }
-
- }
-
- public synchronized void treeStructureChanged(TreeModelEvent e) {
- if (e != null && !this.largeModel) {
- Object[] changedPath = e.getPath();
- VisibleTreeNode var12 = this.getNodeForPath(changedPath, false, false);
- if (var12 == null && changedPath != null && changedPath.length == 1) {
- var12 = this.treeCacheRoot;
- }
-
- if (var12 != null) {
- boolean wasExpanded = var12.isExpanded();
- boolean wasVisible = var12.getRow() != -1;
- if (var12 == this.treeCacheRoot) {
- this.rebuild();
- } else {
- VisibleTreeNode parent = (VisibleTreeNode)((DefaultMutableTreeNode)var12).getParent();
- int nodeIndex = ((DefaultMutableTreeNode)parent).getIndex(var12);
- if (wasVisible && wasExpanded) {
- var12.collapse(false);
- }
-
- if (wasVisible) {
- this.visibleNodes.removeElement(var12);
- }
-
- ((DefaultMutableTreeNode)var12).removeFromParent();
- this.createNodeAt(parent, nodeIndex);
- VisibleTreeNode newNode = (VisibleTreeNode)((DefaultMutableTreeNode)parent).getChildAt(nodeIndex);
- if (wasVisible && wasExpanded) {
- newNode.expand(false);
- }
-
- int parent = newNode.getRow();
- if (!this.isFixedRowHeight() && wasVisible) {
- if (parent == 0) {
- this.updateYLocationsFrom(parent);
- } else {
- this.updateYLocationsFrom(parent - 1);
- }
-
- this.visibleNodesChanged();
- } else if (wasVisible) {
- this.visibleNodesChanged();
- }
- }
- }
- } else if (e != null) {
- Object[] changedPath = e.getPath();
- if (changedPath != null && changedPath.length > 0) {
- if (changedPath.length == 1) {
- this.rebuild();
- } else {
- LargeTreeModelNode changedNode = this.getLargeTreeModelNodeForPath(changedPath, false, false);
- if (changedNode != null) {
- LargeTreeModelNode parent = (LargeTreeModelNode)((DefaultMutableTreeNode)changedNode).getParent();
- boolean wasExpanded = changedNode.isExpanded();
- boolean wasVisible = changedNode.isVisible();
- if (wasVisible && wasExpanded) {
- changedNode.collapse(false);
- ((DefaultMutableTreeNode)changedNode).removeFromParent();
- changedNode = this.getLargeTreeModelNodeForPath(changedPath, false, true);
- changedNode.expand(false);
- } else {
- ((DefaultMutableTreeNode)changedNode).removeFromParent();
- }
-
- if (this.treeSelectionModel != null && wasVisible && wasExpanded) {
- this.treeSelectionModel.resetRowSelection();
- }
-
- if (wasVisible) {
- this.visibleNodesChanged();
- } else {
- parent.modelChildCountChanged();
- }
- }
- }
- }
- }
-
- }
-
- public void updateNodeSizes(boolean updateAll) {
- this.updateNodeSizes = false;
- int counter = 0;
- int aY = 0;
-
- for(int maxCounter = this.visibleNodes.size(); counter < maxCounter; ++counter) {
- VisibleTreeNode node = (VisibleTreeNode)this.visibleNodes.elementAt(counter);
- node.setYOrigin(aY);
- if (updateAll || !node.hasValidSize()) {
- node.updatePreferredSize(counter);
- }
-
- aY += node.getPreferredSize().height;
- }
-
- }
-
- protected void updateYLocationsFrom(int location) {
- if (location >= 0 && location < this.getRowCount()) {
- VisibleTreeNode aNode = this.getNode(location);
- int newYOrigin = aNode.getYOrigin() + aNode.getPreferredSize().height;
- int counter = location + 1;
-
- for(int maxCounter = this.visibleNodes.size(); counter < maxCounter; ++counter) {
- aNode = (VisibleTreeNode)this.visibleNodes.elementAt(counter);
- aNode.setYOrigin(newYOrigin);
- newYOrigin += aNode.getPreferredSize().height;
- }
- }
-
- }
-
- public void valueChanged(TreeSelectionEvent e) {
- if (this.treeSelectionModel != null) {
- TreePath[] paths = this.treeSelectionModel.getSelectionPaths();
- if (paths != null) {
- for(int counter = paths.length - 1; counter >= 0; --counter) {
- this.makeVisible(paths[counter]);
- }
- }
- }
-
- }
-
- public Enumeration visibleNodes() {
- return this.visibleNodes.elements();
- }
-
- public abstract void visibleNodesChanged();
-
- private void writeObject(ObjectOutputStream s) throws IOException {
- Vector values = new Vector();
- s.defaultWriteObject();
- if (this.treeModel != null && this.treeModel instanceof Serializable) {
- values.addElement("treeModel");
- values.addElement(this.treeModel);
- }
-
- if (this.treeSelectionModel != null && this.treeSelectionModel instanceof Serializable) {
- values.addElement("treeSelectionModel");
- values.addElement(this.treeSelectionModel);
- }
-
- s.writeObject(values);
- }
- }
-